package table;

public class ResultCol {
	private String function;
	private String field;
	private String descript;
	
	public String getFieldId(){
		return this.getFunction() + this.getField();
	}
	
	public Object getColValue(Object v) throws Exception{
		try{
			if(this.getFunction().toLowerCase().equalsIgnoreCase("count")){
				if(v != null && v.toString().toLowerCase().matches("([1-9][0-9]*)|([0-9])"))	return Integer.parseInt(v.toString());
				return 0;
			} else if(this.getFunction().toLowerCase().equalsIgnoreCase("sum")){
				if(v != null && v.toString().toLowerCase().matches("([1-9][0-9]*[\\.][0-9]*)|([0-9]\\.[0-9]*)|([1-9][0-9]*)|([0-9])"))	return Float.parseFloat(v.toString());
				return 0;
			}
		} catch (Exception e){
			return v;
		}
		return v;
	}
	
	public void setFunction(String function) {
		this.function = function;
	}
	public String getFunction() {
		return function;
	}
	
	public void setField(String field) {
		this.field = field;
	}
	public String getField() {
		return field;
	}
	public void setDescript(String descript) {
		this.descript = descript;
	}
	public String getDescript() {
		return descript;
	}
	
}
